package com.zc.zby.basicframedemo.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zc.zby.basicframedemo.R;
import com.zc.zby.basicframedemo.databinding.ItemContactBinding;
import com.zc.zby.basicframedemo.model.UserModel;
import com.zc.zby.basicframedemo.present.DataBindPresent;
import com.zc.zby.basicframedemo.viewholder.ContactViewHolder;

import java.util.List;

public class ContactAdapter extends RecyclerArrayAdapter<UserModel> {

    public ContactAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        ViewDataBinding inflate = DataBindingUtil.inflate(layoutInflater, R.layout.item_contact, parent, false);
        return new ContactViewHolder(inflate.getRoot());
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position, @NonNull List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);
        ItemContactBinding binding = DataBindingUtil.getBinding(holder.itemView);
        binding.setUser(getAllData().get(position));
        binding.setUserPresent(new DataBindPresent(this));
        binding.executePendingBindings();
    }
}
